package com.bawei.park2211a.car

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.base.bean.AddCarEntity
import com.bawei.base.mvvm.BaseActivity
import com.bawei.park2211a.R
import com.bawei.park2211a.databinding.ActivityAddCarBinding
import com.bigkoo.pickerview.builder.OptionsPickerBuilder
import com.bigkoo.pickerview.configure.PickerOptions
import com.bigkoo.pickerview.listener.OnOptionsSelectListener
import com.bigkoo.pickerview.view.OptionsPickerView
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/car/AddCarActivity")
@AndroidEntryPoint
class AddCarActivity : BaseActivity<ActivityAddCarBinding,CarViewModel>() {
    var adder=""
    override fun initView() {
        val addCarEntity = AddCarEntity()
        // 初始化一个ArrayList，包含不同的停车区域名称
        val arrayListOf = arrayListOf("A区地下停车位", "B区地下停车位", "C区地下停车位", "D区地下停车位")

        // 创建一个ArrayAdapter实例，用于Spinner组件显示停车区域
        var spinnerAdpter:ArrayAdapter<String> =
            ArrayAdapter(this, com.chad.library.R.layout.support_simple_spinner_dropdown_item, arrayListOf)

        // 设置Spinner组件的适配器
        binding.carSpinner.adapter=spinnerAdpter

        // 设置Spinner组件的监听器，以处理选中停车区域的变化
        binding.carSpinner.onItemSelectedListener=object :OnItemSelectedListener{
            // 当选中的停车区域发生变化时调用
            override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
                // 更新选中的停车区域
                adder=arrayListOf[p2]
            }

            // 当没有选中的停车区域时调用
            override fun onNothingSelected(p0: AdapterView<*>?) {
                // 无需处理
            }
        }
        binding.carLeisure.setOnClickListener {
            binding.carMiantain.setBackgroundResource(R.drawable.shape_button)
            binding.carTakeup.setBackgroundResource(R.drawable.shape_button)
            binding.carLeisure.setBackgroundResource(R.drawable.shape_checkbutton)
        }
        binding.carMiantain.setOnClickListener {
            binding.carLeisure.setBackgroundResource(R.drawable.shape_button)
            binding.carTakeup.setBackgroundResource(R.drawable.shape_button)
            binding.carMiantain.setBackgroundResource(R.drawable.shape_checkbutton)
        }
        binding.carTakeup.setOnClickListener {
            binding.carMiantain.setBackgroundResource(R.drawable.shape_button)
            binding.carLeisure.setBackgroundResource(R.drawable.shape_button)
            binding.carTakeup.setBackgroundResource(R.drawable.shape_checkbutton)
        }
        binding.carType.setOnClickListener {
            val list= mutableListOf<String>()
            list.add("标准车位")
            list.add("豪华车位")
            val Picker = OptionsPickerBuilder(this) { options1, _, _, _ ->
                binding.carType.text = list[options1]
            }
                .setTitleText("请选择停车位")
                .build<String>()
            Picker.setPicker(list)
            Picker.show()
        }
        binding.carSubmit.setOnClickListener {

            addCarEntity.licensePlate= binding.carNumber.text.toString()
            addCarEntity.areaName= adder
            addCarEntity.spaceNumber= binding.carSerial.text.toString()
            addCarEntity.spaceType= binding.carType.text.toString()
            addCarEntity.userName=binding.carUsername.text.toString()
            when(binding.rg.checkedRadioButtonId){
                R.id.car_miantain->{
                    addCarEntity.spaceStatus="维修中"
                }
                R.id.car_leisure->{
                    addCarEntity.spaceStatus="空闲"
                }
                R.id.car_takeup->{
                    addCarEntity.spaceStatus="已占用"
                }
            }
            viewModel.addcar(addCarEntity)
        }

    }

    override fun initData() {

    }
}